function QueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.href.substr(1).match(reg);
	if (r != null) return unescape(decodeURI(r[2]));
	return null;
}

function GetDomain() {

	let domain = window.location.hostname.split('.')[0];
	if (domain == 'localhost') return 'zhengpinkeji';
	return domain;
}

function IsMoney(txt) {
	var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
	if (reg.test(txt)) return true;
	return false;
}

function IsPhone(txt) {
	var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
	if (!myreg.test(txt)) {
		return false;
	} else {
		return true;
	}
}

function IsEmail(txt) {
	var myreg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
	if (!myreg.test(txt)) {
		return false;
	} else {
		return true;
	}
}

function IsBankCard(data){
 var regExp = /^([1-9]{1})(\d{15}|\d{18})$/; 
 return regExp.test(data) 
 } 

function IsChineseName(txt) {
	var myreg = /^[\u4E00-\u9FA5]{2,4}$/;
	if (!myreg.test(txt)) {
		return false;
	} else {
		return true;
	}
}

function showToast(tips) {
	uni.showToast({
		title: tips,
		icon: 'none',
		duration: 2000,
		confirmText: '删除',
		cancelColor: '#171717',
		confirmColor: '#ff5e1f',
	});

}

//获取地址参数
function getQueryVariable(name) {
	var search = location.href.split("?")[1];
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = search.match(reg); //获取url中"?"符后的字符串并正则匹配
	var context = "";
	if (r != null)
		context = r[2];
	reg = null;
	r = null;
	return context == null || context == "" || context == "undefined" ? "" : context;
}

export default {
	QueryString,
	GetDomain,
	IsMoney,
	IsPhone,
	IsChineseName,
	showToast,
	getQueryVariable,
	IsBankCard,
	IsEmail
}
